﻿/*
参考文档： https://ai-cyber-security.feishu.cn/docx/P89ZdNZxEoImKbx3hRucsjTBnbg

*/

using System.Text;

namespace StockModel
{
    internal class Program
    {
        public static string file = @"C:\gitee.com\stock_research\samples\sh.600749.csv";
        public static string samples_path = "C:\\gitee.com\\stock_research\\samples";
        public static string data_path = "C:\\gitee.com\\stock_research\\data";

        [STAThread]
        static void Main(string[] args)
        {
            var dict = Common.LoadStockNames();
            var code = args.Length > 0 ? args[0].ToLower() : "sh.600135";
            if (dict.Keys.Contains(code))
            {
                Console.WriteLine($"current stock: {code} {dict[code]}");
                test_single_stock($@"C:\gitee.com\stock_research\data\{code}.csv", false); // 603707
            }
            else
            {
                Console.WriteLine($"'{code}' does not exist.");
            }
            //test4();


            //Application.Run(new MainForm());
        }


        public static void test4()
        {
            string path = data_path;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("    code         year          money           stock          total          last_avg     this_avg   in_price  out_price  last_avg       x2        x2p");
            foreach (var file in Directory.GetFiles(path))
                sb.AppendLine(test_single_stock(file));
            File.WriteAllText($"result_{DateTime.Now:yyyyMMdd_HHmmss}.txt", sb.ToString());
        }

        public static string test_single_stock(string file = @"C:\gitee.com\stock_research\samples\sh.600749.csv", bool show_details = false)
        {
            // 600749=西藏旅游, 000407=胜利股份
            if (!Path.Exists(file))
            {
                Console.WriteLine($"{file} does not exist.\n");
                return "";
            }

            var infos = StockDayKLine.read_csv(file);

            StringBuilder sb = new StringBuilder();

            for (int year = 2020; year <= 2024; year++)
            {
                var model = new AccountModel() { stock_name = Path.GetFileNameWithoutExtension(file) };
                model.target_year = year;
                if (show_details)
                {
                    model.print_details = show_details;
                    model.print_history = show_details;
                }

                if (model.target_year == 12024)
                {
                    model.in_price = 10.25;
                    model.out_price = model.in_price;
                }

                var res = model.Run(infos);
                sb.AppendLine(res);
            }

            Console.WriteLine();
            return sb.ToString();
        }

        public static void test2()
        {
            var files = Directory.GetFiles("C:\\gitee.com\\stock_research\\data");

            foreach (var file in files)
            {
                if (file.ToLower().EndsWith(".csv") && file.Contains("600749"))
                    new AccountModel().Run(file);
                //break;
            }
        }

    }
}
